Class GuideInfo extends Box
var codeBox;
var codeButton;
var tabBar;
var fileName;
function GuideInfo(index){
	if(!Guide.items) GuideAid.init();
	G.stage.addChild(this);
	this.setSize("f","f");

	var itemArr=Guide.items[0][index];
	this.fileName=itemArr[1];
	this.addChild([
		[{dim:"codeBox",enabled:true,scroll:true,relative:1,visible:false,pos:[0,70,"f","f-80"],bg:"#fff"}],
		[{pos:[0,0,"f",70],bg:["#fff",[,"#ccc"]],shadow:[0,0,5,"#3000"]},
			[Button,{name:"close",pos:[0,0,70,"f"],bg:[,[,,,"#ccc"]],type:3},
				[{pos:["c","c",22,40],bg:[,"2#888","shape",[22,0],[2,20],[22,40]]}]
			],
			[RadioBox,{dim:"tabBar",pos:[70,0,"f-140","f"]},
				[new Button([itemArr[0],"#000",22]),{name:"effect",bg:["#fff",[,,,"#ccc"]],pos:[0,0,"f/2","f"]}],
				[new Button([itemArr[1],"#000",22]),{dim:"codeButton",name:"code",bg:["#fff",[,,,"#ccc"]],pos:["+",0,"f/2","f"]}],
			],
			[Button,{name:"all",pos:["r",0,70,"f"],bg:[,[,,,"#ccc"]],type:3},
				[{enabled:false,pos:["c","c",40,30],bg:[,"2#888","shape",[0,1],[40,1],0,[0,15],[40,15],0,[0,29],[40,29]]}]
			],
		],
	]);
	this.codeBox.div.style.cssText+="padding:10px;"+G.toCssKey("user-select")+":text;font-size:20px";
	var classObj=window[this.fileName];
	Class.new(classObj);
	this.setH(80);
}
function showEffect(){
	G.main.setEnabled(true);
	this.codeBox.setVisible(false);
	this.setH(80);
	this.codeButton.setText(this.fileName);
}
function showCode(fileName){
	G.main.setEnabled(false);
	this.codeBox.setVisible(true);
	this.codeBox.removeChildren();
	this.setH("f");
	var classObj=window[fileName];
	var path="code/"+classObj.__classPath.replace(/\./g,"/")+".js";
	var code=IO.readFile(path).replace(/\r/g,"");
	var arr=code.split("\n");
	var html="";
	for(var i=0;i<arr.length;i++){
		var str=arr[i];
		if(str.indexOf("//")==0){
			for(var j=i+1;j<arr.length;j++){
				var str2=arr[j];
				if(str2.indexOf("//")!=0) break;
				str+="\\n"+str2.slice(2);
				i=j;
			}
		}
		html+=this.getRowHtml(str);
	}
	this.codeBox.div.innerHTML=html;
}
function openAll(){
	var items=[];
	for(var i=0;i<Class.items.length;i++){
		var classObj=Class.items[i];
		var path=classObj.__classPath;
		path=path.replace(/\./g,"/")+".js";
		items.push(path);
	}
	items.sort();
	var dlg=new DlgList(items,[this,this.toOpenAll,items]);
	G.stage.addChild(dlg);
	dlg.alignLeft();
}
function toOpenAll(index,items){
	var path=items[index];
	var fileName=path.slice(0,-3).replace(/[^\/]+\//g,"");
	this.showCode(fileName);
	this.codeBox.div.scrollTop=0;
	this.codeButton.setText(fileName);
	this.tabBar.setIndex(1);
}
function getRowHtml(rowStr){
	var keys=["Class","class","extends","var","public","static","function","for","this","if","else","elseif","continue","break","return","while","switch","case","delete","null","true","false","super","each","new"];
	if(rowStr.indexOf("//")==0){
		var str="";
		var a=rowStr.slice(2).split("\\n");
		for(var i=0;i<a.length;i++){
			var s=a[i];
			if(s.indexOf("<")==0){
				str+="<img src='"+s.slice(1,-1)+"'><br>";
			}
			else{
				str+="<p style='text-indent:"+(a.length==1?0:2)+"em;margin:0px'><font style='font-size:0px'>//#</font>"+s+"</p>";
			}
		}
		return "<div style='font-size:20px;margin:10px;padding:10px;display:block;background:#f6f6f6;border:1px solid #c0c0c0;"+G.toCssKey("border-radius")+":6px'>"+str+"</div>";
	}
	
	if(rowStr=="") rowStr=" ";
	var html="";
	var tabSize=0;
	while(true){
		var s=rowStr.charAt(0);
		if(s!=" "&&s!="\t") break;
		tabSize+=s=="\t"?4:1;
		rowStr=rowStr.slice(1);
	}
	var str="";
	for(var i=0;i<tabSize;i++){
		str+="&nbsp;";
	}
	if(str) html+="<font style='font-size:0px'>"+str+"</font>";
	for(var i=0;i<rowStr.length;i++){
		var s=rowStr.charAt(i);
		var s2=rowStr.charAt(i+1);
		if(s=="\""||s=="'"){
			for(var j=i+1;j<rowStr.length;j++){
				var sj=rowStr.charAt(j);
				if(rowStr.charAt(j-1)!="\\"&&sj==s) break;
			}	
			var str=rowStr.slice(i,j+1);
			i=j;
			html+="<font color='#008000'>"+str+"</font>";
		}
		else if(s=="/"&&s2=="/"){
			for(var j=i+1;j<rowStr.length;j++){
				var sj=rowStr.charAt(j);
			}	
			var str=rowStr.slice(i,j+1);
			i=j-1;
			html+="<font color='#606060'>"+str+"</font>";
		}
		else if(s=="/"){
			for(var j=i+1;j<rowStr.length;j++){
				var sj=rowStr.charAt(j);
				if(rowStr.charAt(j-1)!="\\"&&sj=="/") break;
			}	
			var str=rowStr.slice(i,j+1);
			i=j;
			html+=str;

		}
		else if(this.isLetter(s)){
			for(var j=i+1;j<rowStr.length;j++){
				var sj=rowStr.charAt(j);
				if(!this.isLetter(sj)&&!this.isNumber(sj)) break;
			}
			var str=rowStr.slice(i,j);
			i=j-1;
			var c=s.charCodeAt(0);
			if(keys.indexOf(str)>-1){
				html+="<font color='#2020ff'>"+str+"</font>";
			}
			else if(c>=65&&c<=90){
				html+="<font color='#0080aa'>"+str+"</font>";
			}
			else{
				html+=str;
			}
		}
		else if(this.isNumber(s)){
			for(var j=i+1;j<rowStr.length;j++){
				var sj=rowStr.charAt(j);
				if(sj!="."&&!this.isNumber(sj)) break;
			}
			var str=rowStr.slice(i,j);
			i=j-1;
			html+="<font color='#d00000'>"+str+"</font>";
		}
		else{
			if(s==" ") s="&nbsp;";
			if(s=="<") s="&lt;";
			html+=s;
		}
	}
	return "<div style='text-indent:-40px;word-wrap:break-word;line-height:120%;padding-left:"+(tabSize*10+40)+"px'>"+html+"</div>"
}
function isLetter(s){
	var c=s.charCodeAt(0);
	return s=="_"||(c>=65&&c<=90)||(c>=97&&c<=122);
}
function isNumber(s){
	var c=s.charCodeAt(0);
	return c>=48&&c<=57;
}
function onRemove(){
	G.main.setEnabled(true);
	G.main.removeChildren();
	if(Guide.self) Guide.self.setX(0);
}
function onButtonClick(){
	switch(G.target.name){
		case "close":this.remove();break;
		case "effect":this.showEffect();break;
		case "code":this.showCode(this.fileName);break;
		case "all":this.openAll();break;
	}
}